package com.drako.tdgdx.logic.turret;

import java.util.ArrayList;

import com.badlogic.gdx.graphics.GL10;
import com.drako.tdgdx.helper.GlobalHelper;
import com.drako.tdgdx.logic.GameLogic;
import com.drako.tdgdx.logic.IHazLogic;
import com.drako.tdgdx.logic.IHazRenderable;

public class TowerHandler implements IHazLogic,IHazRenderable{
private GameLogic logic;
private ArrayList<Tower> towers;

public TowerHandler(GameLogic logic){
	this.logic = logic;
	towers = new ArrayList<Tower>();
}
	public void buildTower(Tower tower){
		int tmpMoney = logic.getPlayer().getMoney()-tower.getCosts();
		if(tmpMoney<0){
			tower = null;
					
		}else{
			int x= GlobalHelper.posToArray(tower.getPosition().x);
			int y= GlobalHelper.posToArray(tower.getPosition().y);
			logic.getField().getCollision()[x][y]= true;
		}
	}
	public void upgradeTower(Tower tower){
		int tmpMoney =logic.getPlayer().getMoney()- tower.getUpgradeCosts();
		if(tmpMoney >0){
			tower.upgrade();
		}
	}
	@Override
	public void update() {
		for (Tower tower : towers) {
			tower.update();
		}
		
	}
	@Override
	public void render(GL10 gl) {
		for (Tower tower : towers) {
			tower.render(gl);
		}
		
	}
}
